package com.geek.video.web.response;

import com.geek.video.enums.ResponseEnum;
import reactor.core.publisher.Mono;

/**
 * 返回结果统一处理
 *
 * @author Steven
 */
public class ResponseData {

    private int code;
    private String message;
    private Object data;

    public static final int SUCCESS_CODE = ResponseEnum.SUCCESS.getCode();

    public ResponseData(int code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public ResponseData(int code, String message, Object data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回的结果
     *
     * @param data 封装数据
     * @return 返回封装结果
     */
    public static Mono<ResponseData> ofSuccess(Object data) {

        return Mono.just(new ResponseData(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), data));
    }

    /**
     * 根据枚举值返回结果
     *
     * @param responseEnum
     * @return
     */
    public static Mono<ResponseData> ofStatus(ResponseEnum responseEnum) {

        return Mono.justOrEmpty(new ResponseData(responseEnum.getCode(), responseEnum.getMessage()));
    }

    /**
     * 自定义返回结果
     *
     * @param code
     * @param message
     * @return
     */
    public static Mono<ResponseData> ofMessage(int code, String message) {

        return Mono.fromSupplier(() -> new ResponseData(code, message));
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}